package me.xiaoyan.cloud.controller;

import me.xiaoyan.cloud.repository.UserInfoRepository;
import me.xiaoyan.cloud.pojo.UserInfo;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

@RestController
public class LoginController {
    @Resource
    private UserInfoRepository userInfoRepository;
    @PostMapping("/login")
    public UserInfo login(@RequestBody UserInfo findCondition) {
        final Optional<UserInfo> optional = userInfoRepository.findOne(Example.of(findCondition));
        if(optional.isPresent()){
            return optional.get();
        }
        throw new RuntimeException("账号或密码错误");
    }
}
